home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 30
/
Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso
/
Aminet
/
text
/
hyper
/
GetHelp.lha
/
GetHelp
/
GetHelp.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1999-02-11
|
6KB
|
248 lines
/* GetHelp.rexx - Opens html help file on URL link from a browser
** $VER: GetHelp.rexx 0.9 (10.2.99) by B.Rogers <bsrogers@cobweb.com.au>
** Refer to the documentation for usage, version history etc.
*/
/**************************************
** Set up constants
*/
/* Default html file if no arguments */
default_url='file://localhost/Help:Amiga_help.help'
/* Debug flag (1=true) */
DeBug=0
/**************************************
** Main program
*/
OPTIONS RESULTS
OPTIONS FAILAT 21
ADDRESS COMMAND
PARSE ARG help_url
/* remove any nastly quotes from help_url
** ie rx GetHelp "Help:ag2html.help"
*/
help_url = STRIP(help_url,'B','"')
IF debug=1 THEN SAY help_url
/*
** options are:
** 1. Initial call for Help (default html page)
** 2. Call for a specific help file
** 3. Call to exit Help
**
*/
SELECT
WHEN help_url='QUIT' THEN DO
IF debug=1 THEN SAY 'Quit Message...'
CALL Clean_Up
EXIT
END
WHEN help_url="" THEN DO
/* prepare to display default html file */
url=default_url
first_time=1
/* create T:Help directory
** - this also flags that the help function has been called
*/
IF ~EXISTS("T:Help") THEN DO
IF debug=1 THEN SAY 'Initialising T:Help directory'
'makedir' "T:Help"
END
IF debug=1 THEN SAY "Displaying default help page..."
END
OTHERWISE url = get_url(help_url)
END
/*
** Display url using Openurl
*/
IF debug=1 THEN SAY 'Displaying file...'url
openurl url
/* user has ended help session */
IF first_time=1 THEN DO
SAY 'All done! Exiting...'
CALL Clean_up
END
/* exit gethelp */
EXIT
/**********************************************************
** get a correctly formatted url ready to feed to a browser
*/
get_url:
PARSE ARG help_url
/*
** check for file://localhost/, file:///, http:// or ftp:// paths
*/
pos_local = INDEX(help_url,"file://localhost/")
IF pos_local>0 THEN DO
help_url=RIGHT(help_url,LENGTH(help_url)-17)
IF ~EXISTS(help_url) THEN DO
clean_up
EXIT 10
END
IF debug=1 THEN DO
SAY "Yep, its a local file [file://localhost/]"
SAY help_url
END
END
ELSE DO
pos_local = INDEX(help_url,"file:///")
IF pos_local>0 THEN DO
help_url=RIGHT(help_url,LENGTH(help_url)-8)
IF ~EXISTS(help_url) THEN DO
clean_up
EXIT 10
END
IF debug=1 THEN DO
SAY "Yep, its a local file [file:///]"
SAY help_url
END
END
ELSE DO
pos_http = INDEX(help_url,"http:")
pos_ftp = INDEX(help_url,"ftp:")
IF pos_http>0 OR pos_ftp>0 THEN DO
SAY "Yep, it's online - future capability enhancement!"
clean_up
EXIT
END
END
END
/*
** parse any assigns or devices in path
*/
pos_assign = INDEX(help_url,":")
IF poss_assign>0 THEN DO
path_assign = LEFT(help_url,pos_assign)
/* trim path_assign from help_url */
help_path = RIGHT(help_url,LENGTH(help_url)-pos_assign)
IF debug=1 THEN DO
SAY "Help path="help_path
SAY "Assign path="path_assign
END
END
/*
** now check for / markers
*/
pos_dir = LASTPOS("/",help_path)
IF pos_dir>0 THEN DO
path_dir = LEFT(help_path,pos_dir)
help_file = RIGHT(help_path,LENGTH(help_path)-pos_dir)
END
ELSE DO
/* there were no / markers! */
help_file = help_path
END
/* remove .html suffix */
help_file_name = SUBSTR(help_file,1,LENGTH(help_file)-5)
/* debug info */
IF debug=1 THEN DO
SAY "path dir="path_dir
SAY "help_file="help_file
END
/* set up help directory in T: and first file to show */
help_directory = "T:Help/"help_file_name
help_html = help_file_name".html"
IF debug=1 THEN DO
SAY "help_directory="help_directory
SAY "help_html="help_html
END
/*
** extract html files if not already cached
*/
IF ~EXISTS(help_directory) THEN
DO
/* confirm we have a T:Help directory */
IF ~EXISTS("T:Help") THEN DO
IF debug=1 THEN SAY 'NOTE - a browser has directly accessed a help file!'
'makedir' "T:Help"
/* spawn process to monitor Browser quit */
'RUN >NIL: SYS:Rexxc/rx GetHelp.rexx QUIT'
END
/* create help topic subdirectory */
'makedir' help_directory
IF debug=1 THEN 'lha -I -X x "'help_url'"' help_directory'/'
ELSE 'lha -I -X -q x "'help_url'"' help_directory'/'
END
/*
** select main.html if available, else default to <help_html>.html
*/
IF EXISTS(help_directory"/main.html") THEN help_html = "main.html"
/*
** if neither option found, we have an error!
*/
IF ~EXISTS(help_directory"/"help_html) THEN DO
ADDRESS COMMAND
msg = '"Could not find main.html or 'help_html'..."'
'requestchoice' 'Browser' msg 'Investigate'
CALL clean_up
EXIT
END
/* tell browser where first file will be.. */
url = "file:///"help_directory"/"help_html
RETURN url
/************************************************
** clean up and exit on-line help
*/
clean_up:
ADDRESS COMMAND
/* give browser time to appear! */
'WAIT' 5
/* this line is ugly, but with OpenUrl have no identified way of knowing which browser is in use..*/
DO FOREVER
IF (~SHOW('P','IBROWSE')&~SHOW('P','VOYAGER')&~SHOW('P','AWEB.1')&~SHOW('P','MOREHTML')) THEN BREAK
'WAIT' 5
END
IF debug=1 THEN SAY 'Deleting T: files...'
/* remove T: files */
'delete' ">NIL: T:Help ALL"
'delete' ">NIL: T:temp#?"
'delete' ">NIL: T:Command#?"
IF debug=1 THEN SAY 'Finished!'
RETURN